home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / misc / equations.sty (.txt) < prev    next >
LaTeX Document  |  1989-12-20  |  8KB  |  175 lines

  1. % This file, equations.sty (August 1988), contains a collection of macros
  2. % to aid in constructing displayed equations in LaTeX.  Written by
  3. %   Charles Karney
  4. %   Plasma Physics Laboratory   Phone:   +1 609 243 2607
  5. %   Princeton University        MFEnet:  Karney@PPC.MFEnet
  6. %   PO Box 451                  ARPAnet: Karney%PPC.MFEnet@NMFECC.ARPA
  7. %   Princeton, NJ 08543-0451    Bitnet:  Karney%PPC.MFEnet@ANLVMS.Bitnet
  8. % with some ideas and macros borrowed from John Hobby and Stephen Gildea.
  9. % --------------------USER DOCUMENTATION--------------------
  10. % Use this as a style option, e.g.,
  11. %     \documentstyle[equations]{article}
  12. % These probably don't work in conjunction with the leqno option.
  13. % This implements the following:
  14. % (1) \yesnumber turns on an equation number in an eqnarray* environment
  15. % (just as \nonumber turns it off in an eqnarray environment).  E.g.,
  16. %     \begin{eqnarray*}
  17. %        a &=& b \\
  18. %          & & + c \\
  19. %          & & + d \\
  20. %          & & + e \\
  21. %          & & + f \\
  22. %          & & + g \yesnumber
  23. %     \end{eqnarray*}
  24. % (2) The eqalign environment is just like Plain TeX's \eqalign.  E.g.,
  25. %     \begin{equation}
  26. %           \begin{eqalign}
  27. %              a &= b, \\
  28. %              c &= d.
  29. %           \end{eqalign}
  30. %     \end{equation}
  31. % Note that \begin{equation} \end{equation} or equivalent is needed.
  32. % (3) The eqalignno environment is just like Plain TeX's \eqalignno.  E.g.,
  33. %     \begin{eqalignno}
  34. %        a &= b, \label{foo}\\
  35. %        c &= d. \label{bar}
  36. %     \end{eqalignno}
  37. % Note the absence of \begin{equation} \end{equation}.  \nonumber can be used
  38. % to suppress the equation number.  eqalignno* is the same except that the
  39. % equation numbers are suppressed (unless a \yesnumber appears).
  40. % (4) The eqaligntwo environment is a two-equation per line equivalent of
  41. % eqalignno.  E.g.,
  42. %     \begin{eqaligntwo}
  43. %        a &= b, & x &= y, \label{foo} \\
  44. %        c &= d, & z &= w. \label{bar}
  45. %     \end{eqaligntwo}
  46. % eqaligntwo* is defined similarly.
  47. % (5) The cases environment is just like Plain TeX's \cases.  E.g.,
  48. %     \begin{equation}
  49. %        u(x) =
  50. %           \begin{cases}
  51. %             0, & for $x < 0$,
  52. %             1, & for $x \ge 0$.
  53. %           \end{cases}
  54. %     \end{equation}
  55. % Note the first column is treated as math, the second column as text.
  56. % (6) I've borrowed John Hobby's modifications to the eqnarray environment
  57. % (to fix up the spacing around the operator), and to the \big, \bigg, etc.
  58. % operators (to make them scale with the point size).
  59. % (7) I've borrowed Stephen Gildea's subequations environment, and fixed it
  60. % so that it ignores spaces after the environment and so that you can refer
  61. % both to the overall set of equations and to individual subequations.  E.g.,
  62. %     \begin{subequations} \label{foo}
  63. %       \begin{eqalignno}
  64. %          a &= b, \label{foo-a} \\
  65. %          c &= d, \label{foo-b}
  66. %       \end{eqalignno}
  67. %       text text text text ...
  68. %       \begin{equation}
  69. %          e = f. \label{foo-c}
  70. %       \end{equation}
  71. %     \end{subequations}
  72. % Now \ref{foo}, \ref{foo-a}, \ref{foo-b}, \ref{foo-c}, produce 1, 1a, 1b,
  73. % 1c.
  74. % --------------------END OF USER DOCUMENTATION--------------------
  75. % Fix up eqnarray* so that \yesnumber and \nonumber do the obvious things 
  76. \newif\if@defeqnsw \@defeqnswtrue
  77. % This is John Hobby's (hobby@research.att.com) version to fix up the spacing.
  78. \def\eqnarray{\stepcounter{equation}\let\@currentlabel=\theequation
  79. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  80. \global\@eqnswtrue
  81. \tabskip\@centering\let\\=\@eqncr
  82. $$\halign to \displaywidth\bgroup\hfil\global\@eqcnt\z@
  83.   $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne 
  84.   \hfil$\displaystyle{{}##{}}$\hfil
  85.   &\global\@eqcnt\tw@ $\displaystyle{##}$\hfil 
  86.   \tabskip\@centering&\llap{##}\tabskip\z@\cr}
  87. \def\yesnumber{\global\@eqnswtrue}
  88. \def\@@eqncr{\let\@tempa\relax\global\advance\@eqcnt by \@ne
  89.     \ifcase\@eqcnt \def\@tempa{& & & &}\or \def\@tempa{& & &}\or
  90.      \def\@tempa{& &}\or \def\@tempa{&}\else\fi 
  91.      \@tempa \if@eqnsw\@eqnnum\stepcounter{equation}\fi
  92.      \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  93.      \global\@eqcnt\z@\cr}
  94. % Several formulas like \eqalign (to go inside \begin{equation}
  95. % \end{equation} or $$ $$.
  96. \def\@eqnacr{{\ifnum0=`}\fi\@ifstar{\@yeqnacr}{\@yeqnacr}}
  97. \def\@yeqnacr{\@ifnextchar [{\@xeqnacr}{\@xeqnacr[\z@]}}
  98. \def\@xeqnacr[#1]{\ifnum0=`{\fi}\cr \noalign{\vskip\jot\vskip #1\relax}}
  99. \def\eqalign{\null\,\vcenter\bgroup\openup1\jot \m@th \let\\=\@eqnacr
  100. \ialign\bgroup\strut
  101. \hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil\crcr}
  102. \def\endeqalign{\crcr\egroup\egroup\,}
  103. % \cases
  104. \def\cases{\left\{\,\vcenter\bgroup\normalbaselines\m@th \let\\=\@eqnacr
  105.     \ialign\bgroup$##\hfil$&\quad##\hfil\crcr}
  106. \def\endcases{\crcr\egroup\egroup\right.}
  107. % Several formulas like \eqalignno (doesn't need the $$ $$)
  108. \def\eqalignno{\stepcounter{equation}\let\@currentlabel=\theequation
  109. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  110. \let\\=\@eqncr
  111. $$\displ@y \tabskip\@centering \halign to \displaywidth\bgroup
  112.   \global\@eqcnt\@ne\hfil
  113.   $\@lign\displaystyle{##}$\tabskip\z@skip&\global\@eqcnt\tw@
  114.   $\@lign\displaystyle{{}##}$\hfil\tabskip\@centering&
  115.   \llap{\@lign##}\tabskip\z@skip\crcr}
  116. \def\endeqalignno{\@@eqncr\egroup
  117.       \global\advance\c@equation\m@ne$$\global\@ignoretrue}
  118. % Here's the eqalignno* environment:
  119. \@namedef{eqalignno*}{\@defeqnswfalse\eqalignno}
  120. \@namedef{endeqalignno*}{\endeqalignno}
  121. % Two formulas like \eqalignno (doesn't need the $$ $$)
  122. \def\eqaligntwo{\stepcounter{equation}\let\@currentlabel=\theequation
  123. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  124. \let\\=\@eqncr
  125. $$\displ@y \tabskip\@centering \halign to \displaywidth\bgroup
  126.   \global\@eqcnt\m@ne\hfil
  127.   $\@lign\displaystyle{##}$\tabskip\z@skip&\global\@eqcnt\z@
  128.   $\@lign\displaystyle{{}##}$\hfil\qquad&\global\@eqcnt\@ne
  129.   \hfil$\@lign\displaystyle{##}$&\global\@eqcnt\tw@
  130.   $\@lign\displaystyle{{}##}$\hfil\tabskip\@centering&
  131.   \llap{\@lign##}\tabskip\z@skip\crcr}
  132. \def\endeqaligntwo{\@@eqncr\egroup
  133.       \global\advance\c@equation\m@ne$$\global\@ignoretrue}
  134. \@namedef{eqaligntwo*}{\@defeqnswfalse\eqaligntwo}
  135. \@namedef{endeqaligntwo*}{\endeqaligntwo}
  136. % subequations
  137. %%% File: subeqn.sty
  138. %%% The subequations environment %%%
  139. % Within the subequations environment, the only change is that
  140. % equations are labeled differently.  The number stays the same,
  141. % and lower case letters are appended.  For example, if after doing
  142. % three equations, numbered 1, 2, and 3, you start a subequations
  143. % environmment and do three more equations, they will be numbered
  144. % 4a, 4b, and 4c.  After you end the subequations environment, the
  145. % next equation will be numbered 5.
  146. % Both text and equations can be put inside the subequations environment.
  147. % If you make any improvements, I'd like to hear about them.
  148. % Stephen Gildea
  149. % MIT Earth Resources Lab
  150. % Cambridge, Mass. 02139
  151. % mit-erl!gildea
  152. % gildea@erl.mit.edu
  153. \newtoks\@stequation
  154. \def\subequations{\refstepcounter{equation}%
  155.   \edef\@savedequation{\the\c@equation}%
  156.   \@stequation=\expandafter{\theequation}%   %only want \theequation
  157.   \edef\@savedtheequation{\the\@stequation}% %expanded once
  158.   \edef\oldtheequation{\theequation}%
  159.   \setcounter{equation}{0}%
  160.   \def\theequation{\oldtheequation\alph{equation}}}
  161. \def\endsubequations{%
  162.   \setcounter{equation}{\@savedequation}%
  163.   \@stequation=\expandafter{\@savedtheequation}%
  164.   \edef\theequation{\the\@stequation}%
  165.   \global\@ignoretrue}
  166. % More from John Hobby
  167. % Fix Plain's \bigl, \Bigl, etc. macros so that they try to scale with
  168. % LaTeX size changes.  This uses the fact that \@setsize sets \ht\strutbox
  169. % to be 70% of the normal unstretched baselineskip.
  170. \def\big#1{{\hbox{$\left#1\vcenter to1.428\ht\strutbox{}\right.\n@space$}}}
  171. \def\Big#1{{\hbox{$\left#1\vcenter to2.142\ht\strutbox{}\right.\n@space$}}}
  172. \def\bigg#1{{\hbox{$\left#1\vcenter to2.857\ht\strutbox{}\right.\n@space$}}}
  173. \def\Bigg#1{{\hbox{$\left#1\vcenter to3.571\ht\strutbox{}\right.\n@space$}}}
  174. \endinput
  175.